<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
		height: 600px;
	}
	
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}
</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li><a href="{:U('Users/index')}">会员列表</a></li>
			<li class="active">天使代言人</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		<div class="row panel-body" style="padding-top:0px;">
			<a href="javascript:;" class="btn btn-sm btn-default" onclick="add_daiyan();">添加代言</a>
		</div>
		
		<section class="panel panel-default">
			<div class="table-responsive">
				<table class="table table-striped b-t b-light text-sm">
					<thead>
						<tr>

							<th>id</th>
							<th class="center">代言</th>
							<th class="center" width="150">代言类型</th>

							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody id="list">
						<foreach name="angel_list" item="v">
							<tr>
							<th>{$v.id}</th>
							<th class="center">
								<php>$type=get_angel($v['type_id'],$v['type']);</php>
								{$type}
							</th>
							<th class="center" width="150">
								<php>if($v['type']==1){echo "商品";}</php>
								<php>if($v['type']==2){echo "店铺";}</php>
								<php>if($v['type']==3){echo "分类";}</php>
							</th>

							<th class="center">
								<a href="javascript:;" onclick="edit_daiyan({$v.id},{$v['type_id']},{$v['type']});">编辑</a> |
								<a href="{:U('users/del_angel',array('id'=>$v['id'],'uid'=>$_GET['id']))}" onclick="{if(confirm('确定要删除吗?')){return true;}return false;}">删除</a><br>
							</th>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>



		</section>

	</section>
</div>
<!-- 添加代言 -->
<div class="modal" id="add_daiyan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">添加代言</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style" style="height:160px;overflow:auto;">
					<table class="modal-tab">
						<tbody>
						<tr>
							<td style="width:20%;"><span class="required">*</span>手机号码</td>
							<td colspan="3">
								<input type="text" value="{$user_info.phone}">
								<span id="usernameyz"></span>
							</td>
						</tr>
						<tr>
							<td style="width:20%;"><span class="required">*</span>代言类型</td>
							<td colspan="3">
								<select name="type" id="daiyan_type">
									<option value="1">商品</option>
									<option value="2">店铺 </option>
									<option value="3">分类</option>
								</select>
							</td>
						</tr>
						<tr>
							<td style="width:20%;" class="type_id"><span class="required">*</span>商品ID</td>
							<td colspan="3">
								<input type="text" value="" id="type_id">
							</td>
						</tr>
						<input type="hidden" value="{$_GET['id']}" id="uid">
						</tbody>
					</table>
				</div>
			</div>

			<div class="modal-footer">
				<button class="btn btn-info" onclick="adddaiyan()" id="butSubmit" style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>

</div>

<!-- 编辑代言 -->
<div class="modal" id="edit_daiyan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">编辑代言</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style" style="height:160px;overflow:auto;">
					<table class="modal-tab">
						<tbody>
						<tr>
							<td style="width:20%;"><span class="required">*</span>手机号码</td>
							<td colspan="3">
								<input type="text" value="{$user_info.phone}">
								<span id="usernameyz"></span>
							</td>
						</tr>
						<tr>
							<td style="width:20%;"><span class="required">*</span>代言类型</td>
							<td colspan="3">
								<select name="type" id="daiyan_type_edit">
									<option value="1">商品</option>
									<option value="2">店铺 </option>
									<option value="3">分类</option>
								</select>
							</td>
						</tr>
						<tr>
							<td style="width:20%;" class="type_id"><span class="required">*</span>商品ID</td>
							<td colspan="3">
								<input type="text" value="" id="type_id_edit">
							</td>
						</tr>

						<input type="hidden" value="" id="id_edit">
						</tbody>
					</table>
				</div>
			</div>

			<div class="modal-footer">
				<button class="btn btn-info" onclick="editdaiyan()" id="butSubmit" style="display:inline-block;">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>

</div>
<script>
	function  add_daiyan() {
        $("#add_daiyan").modal("show");
    }
    function  edit_daiyan(id,type_id,type) {
	    $('#daiyan_type_edit').val(type);
	    $('#type_id_edit').val(type_id);
	    $('#id_edit').val(id);
        $("#edit_daiyan").modal("show");
    }
    $(function () {
		$('#daiyan_type').change(function () {
			var id=$('#daiyan_type').val();
			if(id==1){
				$('.type_id').html('<span class="required">*</span>商品ID');
			}
            if(id==2){
                $('.type_id').html('<span class="required">*</span>店铺ID');
            }
            if(id==3){
                $('.type_id').html('<span class="required">*</span>分类ID');
            }
        })
    })
	function adddaiyan() {
        var daiyan_type=$('#daiyan_type').val();
        var uid=$('#uid').val();
        var type_id=$('#type_id').val();
        console.log(daiyan_type);
        console.log(uid);
        console.log(type_id);
        $.ajax({
            type: "post",
            url: "{:U('users/adddaiyan')}",
            data: {
                'daiyan_type': daiyan_type,
                'uid': uid,
                'type_id':type_id
            },
            success: function(data) {
				if(data==1){
					layer.msg('添加成功');
                    setTimeout("location.reload()",1000);
				}
                if(data==0){
                    layer.msg('添加失败');
                }
            }
        });
    }

    function editdaiyan() {
        var daiyan_type_edit=$('#daiyan_type_edit').val();
        var id_edit=$('#id_edit').val();
        var type_id_edit=$('#type_id_edit').val();
        $.ajax({
            type: "post",
            url: "{:U('users/editdaiyan')}",
            data: {
                'daiyan_type_edit': daiyan_type_edit,
                'id_edit': id_edit,
                'type_id_edit':type_id_edit
            },
            success: function(data) {
                if(data==1){
                    layer.msg('修改成功');
                    setTimeout("location.reload()",1000);
                }
                if(data==0){
                    layer.msg('修改失败');
                }
            }
        });

    }
</script>
<include file="Public:footer" />